﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace calculator_a2
{
    public partial class Calculator : Form
    {
        double num1_c = 0;
        double num2_c = 0;
        double result_c = 0;
        string op;
        public Calculator()
        {
            InitializeComponent();
        }

        private void btn_plus_Click(object sender, EventArgs e)
        {
            try
            {
                num1_c= Convert.ToDouble(num1.Text);
                num2_c = Convert.ToDouble(num2.Text);
                result_c = num1_c + num2_c;
                this.result.Text = Convert.ToString(result_c);
            }
            catch
            {
                this.result.Text = "Error";
            }
        }

        private void btn_substract_Click(object sender, EventArgs e)
        {
            try
            {
                num1_c = Convert.ToDouble(num1.Text);
                num2_c = Convert.ToDouble(num2.Text);
                result_c = num1_c - num2_c;
                this.result.Text = Convert.ToString(result_c);
            }
            catch
            {
                this.result.Text = "Error";
            }
        }

        private void btn_multi_Click(object sender, EventArgs e)
        {
            try
            {
                num1_c = Convert.ToDouble(num1.Text);
                num2_c = Convert.ToDouble(num2.Text);
                result_c = num1_c * num2_c;
                this.result.Text = Convert.ToString(result_c);
            }
            catch
            {
                this.result.Text = "Error";
            }
        }

        private void btn_divi_Click(object sender, EventArgs e)
        {
            try
            {
                num1_c = Convert.ToDouble(num1.Text);
                num2_c = Convert.ToDouble(num2.Text);
                if (num2_c == 0)
                {
                    this.result.Text = "Error!A number cannot be divided by 0.";
                }
                else
                {
                    result_c = num1_c / num2_c;
                    this.result.Text = Convert.ToString(result_c);
                }
                
            }
            catch
            {
                this.result.Text = "Error";
            }
        }
    }
}
